<?php
namespace app\api\controller;

use think\Controller;
use think\Db;
use think\Config;

class Order extends Controller
{
    public function getmsg($cid = ''){
        if($cid == ''){
            return '系统出错,请刷新页面';
        }
        if($this->request->isPost()){
            $data = $this->request->param();
            $data['xdip'] = $_SERVER['REMOTE_ADDR'];      //ip
            // $data['xdref'] = $_SERVER['HTTP_REFERER'];    //来源页
            $data['xdtime'] = time();
            $result = Db::name('xdmsg')->insert($data);
            if($result){
                return '恭喜您!下单成功,请耐心等待系统处理';
            }else{
                return '抱歉!下单失败,请重新下单';
            }
        }
    }

    public function bbb(){
        dump(md5('123456'.Config::get('salt')));
    }

    public function getOrderInfo(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $data['create_time'] = date('Y-m-d H:i:s');
            if($data['ref'] == ""){
                $data['ref'] = "直接打开页面";
            }
            $validate_result = $this->validate($data,'Order');
            if($validate_result !== true){
                return json(['msg'=>$validate_result]);
            }else{
                // dump($data);exit();
                $result = Db::name('order')->insert($data);
                if($result){
                    return json(['msg'=>'下单成功,稍后有专人联系']);
                }else{
                    return json(['msg'=>'下单失败,请重新填写下单信息']);
                }
            }
        }else{
            return json(['msg'=>'获取到错误信息']);
        }
    }
}